package main

import (
	"context"
	"fmt"
	"github.com/ravener/discord-oauth2"
	"golang.org/x/oauth2"
	"io/ioutil"
)


func main() {
	var Endpoint = oauth2.Endpoint{
		AuthURL:   "https://discordapp.com/api/oauth2/authorize",
		TokenURL:  "https://discordapp.com/api/oauth2/token",
		AuthStyle: oauth2.AuthStyleInParams,
	}
	conf := &oauth2.Config{
		RedirectURL: "http://127.0.0.1:3000/auth/callback",
		// This next 2 lines must be edited before running this.
		ClientID:     "1044168747751055430",
		ClientSecret: "5LbZ50LA7enQy0gmWVNPqi225lsmf8eY",
		Scopes:       []string{discord.ScopeIdentify},
		Endpoint:     Endpoint,
	}
	code := "HGMgSNTCrYkQEh63JG8Ftu44wTT6tj"
	ctx := context.Background()
	token, err := conf.Exchange(ctx, code)
	if err != nil {
		fmt.Println(err)
		return
	}
	res, err := conf.Client(ctx, token).Get("https://discord.com/api/users/@me")

	if err != nil || res.StatusCode != 200 {
		fmt.Println(err)
		return
	}
	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	fmt.Println(string(body))
}


